package com.ymanage.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.ymanage.entity.Order;
import com.ymanage.service.FinanceIncomeService;

@Controller
@RequestMapping("/templates")
public class FinanceIncomeController {
	
	@Autowired
	private FinanceIncomeService financeIncomeService;

	@RequestMapping("/income.do")
	public ModelAndView income() throws Exception{
		
		ModelAndView mv = new ModelAndView();
		Date date = new SimpleDateFormat("yyyy-MM-dd").parse("2017-09-04");
		
		List<Order> orderList = financeIncomeService.orderList();
		
		
		Double todayMoney = financeIncomeService.getTodayMoney(date);
		Double monthMoney = financeIncomeService.getMonthMoney();
		Double yearMoney = financeIncomeService.getYearMoney();
		Double grossProfit = financeIncomeService.getGrossProfit();
		
		mv.addObject("todayMoney", todayMoney);
		mv.addObject("monthMoney", monthMoney);
		mv.addObject("yearMoney", yearMoney);
		mv.addObject("grossProfit", grossProfit);
		mv.addObject("orderList",orderList);
		mv.setViewName("finance/income");
		return mv;
	}
	
}
